How to check if a value of a nested object already exists in another one